package imu.ming.spring.service;

import imu.ming.spring.User;
import imu.ming.spring.dao.UserDao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {
    @Autowired
    private  UserDao userDao;
    public boolean doLogin(String name,String password){
        List<User> userList = userDao.getUserInfo();
        System.out.println(" for (User user:userList) ");
        for (User user:userList) {
            //说明用户存在
//            System.out.println("user.getUserName()"+user.getUserName());
            System.out.println(user.getUserName());
            System.out.println(name);
            if( name.equals(user.getUserName()) ){
                System.out.println("user.getUserName()"+user.getUserName());

                if(password.equals(user.getPassword())){
                    System.out.println("登录成功");

//                    flag=true;

                    return  true;
                }else{

                    System.out.println("密码错误");

                    return  false;
                }
            }

        }
        System.out.println(" return  false");
        return  false;

    }
}
